
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:wis_flutter/wis_component/notification/notificationChannel.dart';
import 'package:wis_flutter/wis_component/notification/notificationEnum.dart';


typedef ParamCallback=void Function(NotificationModel notificationModel);

typedef AndroidNotificationDetailsCallback=void Function(AndroidNotificationDetails androidNotificationDetails);

typedef IOSNotificationDetailsCallback=void Function(IOSNotificationDetails iosNotificationDetails);

class NotificationModel{
  final int id;
  final String title;
  final String body;
  final String payload;
  StyleInformation styleInformation;

  NotificationChannel channel;

  String sound;

  String icon;
  List<NotificationEnum> notificationTypes;
  bool success;

  setSuccess(bool suc){
    this.success=suc;
  }

  setStyleInformation(styleInformation){
    this.styleInformation=styleInformation;
  }

  setSound(sound){
    this.sound=sound;
  }

  String resourcePath;//资源地址
  String routePath;

  ParamCallback click;

  ParamCallback beforeNotification;

  AndroidNotificationDetailsCallback androidBeforeSetDetails;

  IOSNotificationDetailsCallback iosBeforeSetDetails;

  ParamCallback successNotification;

  ParamCallback beforeDownload;

  ParamCallback afterDownload;//点击后的路由跳转


  NotificationModel({@required this.id, @required this.title, @required this.body, @required this.payload,
    this.click,this.success,this.beforeDownload,this.afterDownload,this.channel,this.successNotification,
    this.iosBeforeSetDetails,this.androidBeforeSetDetails,this.resourcePath,this.styleInformation
  }){
    if(this.notificationTypes == null || this.notificationTypes.isEmpty){
      this.notificationTypes=new List();
      this.notificationTypes.add(NotificationEnum.NOTIFICATION);
    }
    if(this.icon == null ){//icons 需要配置在 android/app/src/main/res/drawable 目录下
      this.icon="app_icon";
    }

    if(this.channel == null){
      Random random = new Random();
      String nextInt = (random.nextInt(10000) * random.nextDouble()).toString()+random.hashCode.toString();
      channel= new NotificationChannel(id:nextInt,channelDes: "wis_platform_app_chanel",channelName: "wis_platform_app");
    }
  }
}

